import jieba

with open('我与地坛.txt', 'r', encoding='utf-8') as f:
    content = f.read()

words = jieba.cut(content)
words = [word for word in words if word.isalnum()]
words = [word for word in words if len(word) > 1]

word_freq = {}
for word in words:
    if word in word_freq:
        word_freq[word] += 1
    else:
        word_freq[word] = 1

sorted_word_freq = sorted(word_freq.items(), key=lambda x: x[1], reverse=True)

with open('词频排序.txt', 'w', encoding='utf-8') as f:
    for word, freq in sorted_word_freq:
        f.write(f'{word}: {freq}\n')
